/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package appweb;

import java.awt.Color;
import java.awt.Insets;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Button;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.CheckMenuItemBuilder;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.RadioMenuItemBuilder;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @author Diego
 */
public class AppWeb extends Application {
    
    @Override
    @SuppressWarnings("empty-statement")
    public void start(Stage primaryStage) throws SQLException {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
        
GridPane gridpane = new GridPane();
//gridpane.setPadding(new Insets(5));
gridpane.setHgap(5);
gridpane.setVgap(5);
Label space = new Label("");
Label fNameLbl = new Label("Enviar");
TextField fNameFld = new TextField();
Label lNameLbl = new Label("Despliegue");
TextField lNameFld = new TextField();
Button saveButt = new Button("Guardar");
Button displayButt = new Button("Desplegar");
//Crea espacio en blanco 
GridPane.setHalignment(space, HPos.RIGHT);
gridpane.add(space, 0, 0);

// First name label
GridPane.setHalignment(fNameLbl, HPos.RIGHT);
gridpane.add(fNameLbl, 0, 0);
// Last name label
GridPane.setHalignment(lNameLbl, HPos.RIGHT);
gridpane.add(lNameLbl, 0, 1);
// First name field
GridPane.setHalignment(fNameFld, HPos.LEFT);
gridpane.add(fNameFld, 1, 0);
// Last name field
GridPane.setHalignment(lNameFld, HPos.LEFT);
gridpane.add(lNameFld, 1, 1);
// Save button
GridPane.setHalignment(saveButt, HPos.RIGHT);
gridpane.add(saveButt, 1, 2);
//Desplegar boton 
GridPane.setHalignment(saveButt, HPos.RIGHT);
gridpane.add(displayButt, 1, 2);
root.getChildren().add(gridpane);



MenuBar menuBar = new MenuBar();
// File menu - new, save, exit
Menu menu = new Menu("Archivo");
menu.getItems().add(new MenuItem("Nuevo"));
menu.getItems().add(new MenuItem("Salvar"));
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().add(new MenuItem("Salir"));
menuBar.getMenus().add(menu);
// Cameras menu - camera 1, camera 2
Menu tools = new Menu("Activar");
tools.getItems().add(CheckMenuItemBuilder.create()
.text("Vista 1")
.selected(true)
.build());
tools.getItems().add(CheckMenuItemBuilder.create()
.text("Vista 2")
.selected(true)
.build());
menuBar.getMenus().add(tools);
// Alarm
Menu alarm = new Menu("Alarmas");
ToggleGroup tGroup = new ToggleGroup();
RadioMenuItem soundAlarmItem = RadioMenuItemBuilder.create()
.toggleGroup(tGroup)
.text("Sonar Alarma")
.build();
RadioMenuItem stopAlarmItem = RadioMenuItemBuilder.create()
.toggleGroup(tGroup)
.text("Apagar alarma")
.selected(true)
.build();
alarm.getItems().add(soundAlarmItem);
alarm.getItems().add(stopAlarmItem);
Menu contingencyPlans = new Menu("Planes de contingencia");
contingencyPlans.getItems().add(new CheckMenuItem("Autodestrui en 5 segundos"));
contingencyPlans.getItems().add(new CheckMenuItem("Explotar bomba de neutrones "));
contingencyPlans.getItems().add(new CheckMenuItem("Traer a Bane "));
alarm.getItems().add(contingencyPlans);
menuBar.getMenus().add(alarm);

menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
root.getChildren().add(menuBar);
primaryStage.setScene(scene);
primaryStage.show();

String var = "diego";


Connection c = null;
 Statement stmt = null;
        c = DBConnect.connect();
//      try{
//      //  c = DBConnect.connect();
//
//        String SQL = "select * from WebApp.costumer";
//
//        ResultSet rs = c.createStatement().executeQuery(SQL);
//        System.out.println (rs);
//
//      }catch(Exception e){
//          System.out.println("Error on DB connection");
//      }
        
          
      stmt = c.createStatement();
      String sql;
      sql = ("SELECT name FROM costumer" );
      ResultSet rs = stmt.executeQuery(sql);

      //STEP 5: Extract data from result set
      while(rs.next()){
         //Retrieve by column name
        
         String Name = rs.getString("Name");
        

         //Display values
       
         System.out.println(", Last: " + Name);
      }
      //STEP 6: Clean-up environment
      rs.close();
      stmt.close();
      c.close();
          
          
          
        
    }

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
//     * @param args the command line arguments
//     */
//    public static void main(String[] args) {
//        launch(args);
//    }
}
